package com.wanban.base

import android.app.Activity
import android.content.Intent
import android.content.res.Resources
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.wanban.adutils.AdUtils
import com.wanban.tools.AdapterScreenUtils

open class BaseActivity: AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (ignoreHomeLauncher(this)) return

    }

    fun isActivityNotActive(): Boolean{
        return isFinishing || isDestroyed
    }
    /**
     * 适配360
     */
    override fun getResources(): Resources? {
        val res = super.getResources()
        return AdapterScreenUtils.adaptScreen(this, res, 360)
    }

    /**
     * 防止按home退出后，再次进入app的时候重新启动
     */
    private fun ignoreHomeLauncher(activity: Activity): Boolean {
        try {
            if (!activity.isTaskRoot) {
                val intent = activity.intent
                val action = intent.action
                if (action != null && intent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN == action) {
                    activity.finish()
                    return true
                }
            }
        } catch (e: java.lang.Exception) {
            e.printStackTrace()
        }
        return false
    }



    override fun onResume() {
        // 注册reopen广告
        super.onResume()
        AdUtils.onResume(this)
    }

    override fun onPause() {
        super.onPause()
        AdUtils.onPause(this)
    }

}